<!DOCTYPE html>
<html lang="en">
<head>
    <title>余额</title>
    <#include "../inc/header.ftl"/>
</head>

<body class="no-skin">

<div class="main-container ace-save-state" id="main-container">

    <div class="main-content">
        <div class="main-content-inner">

            <div class="page-content">
                <div class="row">
                    <div id="grid-main-data" class="col-xs-12">
                        <table id="MainGrid" style="min-height: 500px"></table>
                        <div id="toolbar">
                            <div style="padding:8px">
                                银行账号：<input id="accountcodeTwo" name="accountcodeTwo">
                                日期：<input id="accountdate" class="easyui-datebox" style="width:140px">&emsp;
                                <a href="#" onclick="javascript:searchInfo()" class="easyui-linkbutton" iconCls="icon-search">查 询</a>

                            </div>
                            <div style="padding:8px 8px 4px">
                                <a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick="javascript:saveInfo()">新增</a>
                                <a href="#" class="easyui-linkbutton" iconCls="icon-edit" onclick="javascript:editInfo()">修改</a>
                                <a href="#" class="easyui-linkbutton" iconCls="icon-remove" onclick="javascript:deleteInfo()">删除</a>
                                <a href="#" class="easyui-linkbutton" iconCls="icon-send" onclick="javascript:sendInfo()">发送</a>
                                <a href="#" class="easyui-linkbutton" iconCls="icon-print" onclick="javascript:exportInfo()">导出</a>

                            </div>
                        </div>
                    </div>
                </div><!-- /.row -->
            </div><!-- /.page-content -->

            <div id="box-add" class="ui-dialog-content hide">
                <form class="form-horizontal" id="form-add" method="post">
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2 no-padding-right">请选择银行账户:&nbsp;</label>
                        <div class="col-xs-12 col-sm-4">
                                    <span class="block input-icon input-icon-right">
                                        <input type="text" name="bankid" id="bankid" class="col-xs-12 easyui-textbox" readonly="true" data-options="required:true" style="width: 100%;" />
                                    </span>
                        </div>
                        <label class="control-label col-xs-12 col-sm-2 no-padding-right">账户名称:&nbsp;</label>
                        <div class="col-xs-12 col-sm-4">
                                    <span class="block input-icon input-icon-right">
                                        <input type="text" name="accountname" id="accountname" class="col-xs-12 easyui-validatebox" readonly="true" data-options="required:true">
                                    </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2 no-padding-right">账户:&nbsp;</label>
                        <div class="col-xs-12 col-sm-4">
                                    <span class="block input-icon input-icon-right">
                                        <input type="text" name="accountcode" id="accountcode" class="col-xs-12 easyui-validatebox" readonly="true" data-options="required:true" />
                                    </span>
                        </div>
                        <label class="control-label col-xs-12 col-sm-2 no-padding-right">银行名称:&nbsp;</label>
                        <div class="col-xs-12 col-sm-4">
                                    <span class="block input-icon input-icon-right">
                                        <input type="text" name="bankname" id="bankname" class="col-xs-12 easyui-validatebox" readonly="true" data-options="required:true">
                                    </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2 no-padding-right">余额:&nbsp;</label>
                        <div class="col-xs-12 col-sm-4">
                                    <span class="block input-icon input-icon-right">
                                        <input type="text" name="fund" id="fund" class="col-xs-12 easyui-numberbox" data-options="precision:2,required:true" style="width:100%" />
                                    </span>
                        </div>
                        <label class="control-label col-xs-12 col-sm-2 no-padding-right">日期:&nbsp;</label>
                        <div class="col-xs-12 col-sm-4">
                                    <span class="block input-icon input-icon-right">
                                        <input type="text" name="accountdate" id="accountdate" class="col-xs-12 easyui-datebox" style="width: 165px" data-options="required:true" />
                                    </span>
                        </div>
                    </div>
                </form>
            </div><!-- #dialog-confirm -->

            <div id="SendBox-add" class="ui-dialog-content hide">
                <div style="padding:8px">
                    复核用户编码：<input id="usercode" class="easyui-textbox" style="width:110px" data-options="required:true" >&emsp;
                    复核用户密码：<input id="userpwd" class="easyui-passwordbox" style="width:110px" data-options="required:true" >&emsp;
                    <a href="#" class="easyui-linkbutton" iconCls="icon-redo"  onclick="javascript:pageSendInfo()"><span  id="sendClean">确认发送</span></a>
                </div>
                <table id="SendMainGrid"></table>
            </div>
        </div>
    </div><!-- /.main-content -->
</div><!-- /.main-container -->

<!-- basic scripts -->
<#include "../inc/basicjs.ftl"/>

<!-- inline scripts related to this page -->
<script type="text/javascript">
    //列表-------------------------------------------------
    jQuery(function($) {
        var curr_time = new Date();
        curr_time.setDate(curr_time.getDate()-1);
        var str = curr_time.getFullYear()+"-";
        str += curr_time.getMonth()+1+"-";
        str += curr_time.getDate();
        $('#accountdate').datebox('setValue',str);

        $('#MainGrid').datagrid({
            url: prefix + '/bill/bankbalance/findBankBalancePage',
            checkbox: true,
            pagination: true,
            fitColumns:false,
            striped: true,
            singleSelect: true,
            loadMsg: "正在加载数据，请稍后...",
            queryParams: {accountcode:'',accountdate:$('#accountdate').val()},
            columns:[[
                {field: 'ck', checkbox: true},
                { title: '帐户名称', field: 'accountname',width:200},
                { title: '账户', field: 'accountcode',width:150},
                { title: '银行名称',	field: 'bankname',width:200},
                { title: '余额',	field: 'fund',width:120},
                { title: '日期',	field: 'accountdate',width:100}
            ]],
            toolbar: '#toolbar',
            onLoadSuccess: function (data) {
                if (data.total == 0) {
                    $('#grid-main-data').find('.datagrid-body').html('<div style="text-align: center;font-size: 14px;padding: 20px 0;">查询无数据</div>');
                }
            }
        });

        $(window).resize(function() {
            $('#MainGrid').datagrid('resize');
        });
        // 查询账户
         $('#accountcodeTwo').combogrid({
            panelWidth:550,
            idField:'accountcode',
            textField:'accountcode',
            data: _bankdata,
            columns:[[
                {field: 'ck', checkbox: true},
                {field:'cantonname',title:'区划',width:80},
                {field:'accountcode',title:'账号',width:160},
                {field:'bankname',title:'开户行名称',width:260}
            ]]
        });
       $('#bankid').combogrid({
            panelWidth:230,
            idField:'bankid',
            textField:'accountname',
            data: _bankdata,
            columns:[[
                {field:'accountname',width:230}
            ]],
            onChange: function(){
                var g = $('#bankid').combogrid('grid');	// get datagrid object
                var r = g.datagrid('getSelected');
                if(r!=null){
                    $('#bankname').val(r.bankname);
                    $('#accountcode').val(r.accountcode);
                    $('#accountname').val(r.accountname);
                }
            }
        });
        // 发送复核表格
        $('#SendMainGrid').datagrid({
            pagination: false,
            fitColumns:false,
            striped: true,
            singleSelect: false,
            loadMsg: "正在加载数据，请稍后...",
            columns:[[
                { title: '帐户名称', field: 'accountname',width:200},
                { title: '账户', field: 'accountcode',width:150},
                { title: '银行名称',	field: 'bankname',width:200},
                { title: '余额',	field: 'fund',width:120},
                { title: '日期',	field: 'accountdate',width:100}
            ]]
        });
    });

    function searchInfo() {
        var accountcode = $('#accountcodeTwo').val();
        var accountdate = $('#accountdate').val();
        if (accountcode == '' && accountdate == '') {
            $.messager.alert('提示', '请选择缴款账户或日期', 'info');
            return;
        }
        $('#MainGrid').datagrid('load', {
            accountcode: accountcode,
            accountdate: accountdate
        });
    }


    //  修改页面框赋值----------------------------------------------
    function editInfo() {
        var row = $('#MainGrid').datagrid('getSelected');
        if (row == null) {
            $.messager.alert('Info', '请选择要编辑的数据', 'info');
            return;
        }
        $('#form-add').form('load',row);
        $('#bankid').combo('readonly', true);
        showForm(2);
    }

    //  新增页面框赋值----------------------------------------------
    function saveInfo() {
        $('#form-add').form('clear');
        $('#bankid').combo('readonly', false);
        showForm(1);

    }



    function showForm(opt) {
        var tit = (opt == 1) ? '添加' : '编辑';
        $( "#box-add" ).removeClass('hide').dialog({
            title: '&nbsp;' + tit,
            iconCls:'icon-add',
            width: 600,
            height: 400,
            modal: true,
            buttons:[{
                text:'保存',
                iconCls:'icon-ok',
                width:80,
                plain:false,
                handler:function(){
                    updateInfo(opt);
                }
            },{
                text:'取消',
                iconCls:'icon-cancel',
                width:80,
                plain:false,
                handler:function(){$('#box-add').dialog('close')}
            }]
        });
    }
    //余额添加修改
    function updateInfo(opt) {
        var url = (opt == 1) ? '/bill/bankbalance/insertBankBalance' :'/bill/bankbalance/updateBankBalance';
        $('#form-add').form({
            url: prefix + url,
            onSubmit:function(){
                var isValid = $(this).form('validate');
                if (isValid){
                    $.messager.progress({
                        title: '提示',
                        msg: '数据处理中，请稍候……',
                        text: ''
                    });
                }
                return isValid;
            },
            success:function(data) {
                $.messager.progress('close');
                var data = eval('(' + data + ')');
                if (data.success) {
                    searchInfo();
                    $('#box-add').dialog('close');
                } else {
                    $.messager.alert('提示', data.msg, '提示');
                }
            }
        });
        $('#form-add').submit();
    }

    function deleteInfo() {
        row = $('#MainGrid').datagrid('getSelected');
        if (row == null) {
            $.messager.alert('Info', '请选择要删除的数据', 'info');
            return;
        }

        $.messager.confirm('确认','您确认想要删除记录吗？',function(r){
            if (r){
                $.ajax({
                    url: prefix +'/bill/bankbalance/deleteBankBalance',
                    type: 'POST',
                    data: {bankid:row.bankid, accountdate: row.accountdate},
                    dataType: 'json',
                    success:function(data){
                        searchInfo();
                        $.messager.alert('提示', data.msg, '提示');
                    }
                });
            } else{//没选中
                return false;
            }
        })
    }

    //----------------------- 发送弹窗
    function sendInfo() {
        var row = $('#MainGrid').datagrid('getSelections');
        if (row.length == 0) {
            $.messager.alert('提示', '请选择要发送的数据', 'info');
            return;
        }

        $('#usercode').textbox('setValue', '');
        $('#userpwd').textbox('setValue', '');

        var tit = '发送余额';
        $('#sendClean').text('确认发送');

        $( "#SendBox-add" ).removeClass('hide').dialog({
            title: '&nbsp;'+tit,
            iconCls:'icon-send',
            width: 600,
            height: 500,
            modal: true,
            buttons:[{
                text:'取消',
                iconCls:'icon-cancel',
                width:80,
                plain:false,
                handler:function(){$('#SendBox-add').dialog('close')}
            }]
        });

        // 右侧表格
        $('#SendMainGrid').datagrid({
            data:row,
        });
    }
    //  ----------------确认发送
    function pageSendInfo() {
        var usercode = $('#usercode').val();
        var userpwd = $('#userpwd').val();
        if(usercode==null||usercode==''){
            $.messager.alert('提示', '请输入用户编码', '提示');
            return;
        }
        if(userpwd==null||userpwd==''){
            $.messager.alert('提示', '请输入用户密码', '提示');
            return;
        }
        
        var row = $('#MainGrid').datagrid('getSelected');
        $.messager.progress({
           title: '提示',
           msg: '数据处理中，请稍候……',
           text: ''
        });
        $.ajax({
            url: prefix +'/bill/bankbalance/sendBankBalance',
            type: 'POST',
            data: {
                usercode: usercode,
                userpwd:userpwd,
                bankid:row.bankid,
                accountdate:row.accountdate
            },
            dataType: 'json',
            success:function(data){
                $.messager.alert('提示', data.msg, 'info', function() {
                    if (data.success) $('#SendBox-add').dialog('close');
                    $.messager.progress('close');
                });
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                $.messager.alert('提示', '提交失败', 'info');
                $.messager.progress('close');
            }
        });
    }

    function cancelInfo() {
        $('#SendBox-add').dialog('close')
    }
    function exportInfo() {
        var accountcode = $('#accountcodeTwo').val();
        var accountdate = $('#accountdate').val();
        if (accountcode == '' && accountdate == '') {
            $.messager.alert('提示', '请选择缴款账户或日期', 'info');
            return;
        }

        var downurl = prefix + '/bill/bankbalance/findBankBalanceExport?1=1'
        accountcode == "" ? downurl = downurl : downurl = downurl + "&accountcode=" + accountcode;
        accountdate == "" ? downurl = downurl : downurl = downurl + "&accountdate=" + accountdate;
        window.location.href = downurl;
    }


</script>
</body>
</html>
